﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/UserMaster.master" Inherits="System.Web.Mvc.ViewPage<Eacademy.Domain.Models.AdminSubjectListViewModel>" %>

<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {
            $(".subject a").click(function () {
                $(this).siblings(".mentors").slideToggle();
                return false;
            });
            $(".delete-subject-link").live("click", function (event) {
                event.preventDefault();
                var $link = $(this);
                $("#dialog-confirm").dialog({
                    resizable: false,
                    height: 120,
                    modal: true,
                    position: 'fixed',
                    draggable: false,
                    buttons: {
                        "Continue": function () {
                            $(this).dialog("close");
                            $.post($link.attr("href"), null, reloadPage);
                        },
                        Cancel: function () {
                            $(this).dialog("close");
                        }
                    }
                });
            })
        });

        function reloadPage() { location.reload(true); }
    </script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Subjects
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h3>
        Subject List</h3>
    <%=Html.Grid(Model.SubjectList).Columns(column =>
      {
          column.For(x => x.SubjectCode).Sortable(true);
          column.For(x => x.SubjectName).Sortable(true);
          column.For(x => x.Enrolled).Sortable(true).Named("Students Enrolled").CustomItemRenderer =
               (context, item) => context.Writer.Write("<td>" + Html.ActionLink("View(" + item.Enrolled + ")", "View", new { Controller = "Students", id = item.SubjectId, status = true  }) + "</td>");
          column.For(x => x.PendingEnrollment).Sortable(true).Named("Pending Request").CustomItemRenderer =
              (context, item) => context.Writer.Write("<td>" + Html.ActionLink("View(" + item.PendingEnrollment + ")", "View", new { Controller = "Students", id = item.SubjectId, status = false  }) + "</td>");
          column.For(x => Html.ActionLink("View Lessons", "Index", new { Controller = "Lessons", id = x.SubjectId }));
          column.For(x => Html.ActionLink("View Assignments", "Index", new { Controller = "Assignments", id = x.SubjectId }));
          column.For(x => Html.ActionLink("View Quizzes", "Index", new { Controller = "Quizzes", id = x.SubjectId }, new { @class = "choose-mentor", id = "quizsbj-" + x.SubjectId }));
      }).Sort(Model.GridSortOptions)
            .Attributes(@id => "grid-style" , cellspacing => "0",cellpadding => "0")
            .Empty("No subjects")%>
    <div class="event-paging">
        <div class="pager">
            <% if (Model.SubjectList.TotalItemCount > Model.SubjectList.PageSize)
               {%>
            <%= Html.Pager(Model.SubjectList.PageSize, Model.SubjectList.PageNumber, Model.SubjectList.TotalItemCount)%>
            <%} %>
        </div>
    </div>
    <div id="dialog-confirm" title="Delete this subject?" style="display: none;">
        <p>
            Are you sure you want to delete this subject? Lessons under this subject will also
            be deleted</p>
    </div>
</asp:Content>
